/**
 * 系统设置状态
 * Copyright (c) 2023 dfec
 */

// 引入系统配置文件
import defaultSettings from '@/settings'
const {
    theme,
    showThemeSwitch,
    showLogo,
    showTitle,
    showMessage,
    size
} = defaultSettings
const state = {
    // 皮肤
    theme: theme,
    // 是否显示设置皮肤功能
    showThemeSwitch: showThemeSwitch,
    // 是否显示系统logo
    showLogo: showLogo
        ? require(`@/assets/images/pic-logo-${theme}.png`)
        : false,
    // 是否显示系统标题
    showTitle: showTitle ? process.env.VUE_APP_TITLE : false,
    // 是否显示消息控件
    showMessage: showMessage,
    // 系统控件尺寸
    size: size
}
const mutations = {
    /**
     * 修改设置
     * @param {Object} state
     * @param {Object} param1
     */
    CHANGE_SETTING: (state, { key, value }) => {
        // eslint-disable-next-line no-prototype-builtins
        if (state.hasOwnProperty(key)) {
            state[key] = value
        }
    }
}
const actions = {
    /**
     * 修改设置
     * @param {*} param0
     * @param {*} param1
     */
    changeSetting({ commit }, { key, value }) {
        commit('CHANGE_SETTING', { key, value })
        // 如果切换了皮肤，就将logo也切换掉
        if (key === 'theme') {
            commit('CHANGE_SETTING', {
                key: 'showLogo',
                value: showLogo
                    ? require(`@/assets/images/pic-logo-${state.theme}.png`)
                    : false
            })
        }
    }
}
export default {
    namespaced: true,
    state,
    mutations,
    actions
}
